package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.shop.ShopAppraiseDto;
import com.java110.intf.goods.IShopAppraiseInnerServiceSMO;
import com.java110.mall.goods.dao.IShopAppraiseServiceDao;
import com.java110.po.shop.ShopAppraisePo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 商品评论内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class ShopAppraiseInnerServiceSMOImpl extends BaseServiceSMO implements IShopAppraiseInnerServiceSMO {

    @Autowired
    private IShopAppraiseServiceDao shopAppraiseServiceDaoImpl;


    @Override
    public int saveShopAppraise(@RequestBody ShopAppraisePo shopAppraisePo) {
        int saveFlag = 1;
        shopAppraiseServiceDaoImpl.saveShopAppraiseInfo(BeanConvertUtil.beanCovertMap(shopAppraisePo));
        return saveFlag;
    }

    @Override
    public int updateShopAppraise(@RequestBody ShopAppraisePo shopAppraisePo) {
        int saveFlag = 1;
        shopAppraiseServiceDaoImpl.updateShopAppraiseInfo(BeanConvertUtil.beanCovertMap(shopAppraisePo));
        return saveFlag;
    }

    @Override
    public int deleteShopAppraise(@RequestBody ShopAppraisePo shopAppraisePo) {
        int saveFlag = 1;
        shopAppraisePo.setStatusCd("1");
        shopAppraiseServiceDaoImpl.updateShopAppraiseInfo(BeanConvertUtil.beanCovertMap(shopAppraisePo));
        return saveFlag;
    }

    @Override
    public List<ShopAppraiseDto> queryShopAppraises(@RequestBody ShopAppraiseDto shopAppraiseDto) {

        //校验是否传了 分页信息

        int page = shopAppraiseDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            shopAppraiseDto.setPage((page - 1) * shopAppraiseDto.getRow());
        }

        List<ShopAppraiseDto> shopAppraises = BeanConvertUtil.covertBeanList(shopAppraiseServiceDaoImpl.getShopAppraiseInfo(BeanConvertUtil.beanCovertMap(shopAppraiseDto)), ShopAppraiseDto.class);

        return shopAppraises;
    }


    @Override
    public int queryShopAppraisesCount(@RequestBody ShopAppraiseDto shopAppraiseDto) {
        return shopAppraiseServiceDaoImpl.queryShopAppraisesCount(BeanConvertUtil.beanCovertMap(shopAppraiseDto));
    }

    public IShopAppraiseServiceDao getShopAppraiseServiceDaoImpl() {
        return shopAppraiseServiceDaoImpl;
    }

    public void setShopAppraiseServiceDaoImpl(IShopAppraiseServiceDao shopAppraiseServiceDaoImpl) {
        this.shopAppraiseServiceDaoImpl = shopAppraiseServiceDaoImpl;
    }
}
